package com.sgb.kjwl.view.ui.adapter.business;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.business.ApprovalFlowEntity;
import com.sgb.kjwl.view.widget.RtlGridLayoutManager;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.recyclerview.adapter.PageRecycleAdapter;

import java.util.List;

/**
 * 审批流的部门
 */
public class ApprovalDepartAdapter extends PageRecycleAdapter<ApprovalFlowEntity.ApproverBean> {

    public ApprovalDepartAdapter(Context context, List<ApprovalFlowEntity.ApproverBean> datas) {
        super(context, R.layout.item_approval_dept, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, ApprovalFlowEntity.ApproverBean entity) {
        holder.setBinding(BR.viewModel, entity);

        TextView status = holder.itemView.findViewById(R.id.tv_status);
        TextView reason = holder.itemView.findViewById(R.id.tv_reason);

        if (!TextUtils.isEmpty(entity.getStatusStr())) {
            status.setText(entity.getDepart() + "(" + entity.getStatusStr() + ")");
        } else {
            status.setText(entity.getDepart());
        }

        if (!TextUtils.isEmpty(entity.getReason())) {
            reason.setText("拒绝原因：" + entity.getReason());
        }

        RecyclerView list = holder.itemView.findViewById(R.id.person_list);
        ApprovalFlowAdapter adapter = new ApprovalFlowAdapter(context, null);
        list.setAdapter(adapter);
        list.setLayoutManager(new RtlGridLayoutManager(context, 2));
        adapter.setDatas(entity.getApproverList());
    }
}
